'''
Created on 2012-8-16

@author: johnny
'''
import time
import unittest
import cmd
import vm

class Test(unittest.TestCase):


    def setUp(self):
        pass


    def tearDown(self):
        pass


    def testName(self):
        self.vm = vm.VMS("vm-test")
        self.vm.set_cfg('numVcpusAllocated', '2')
        self.control = cmd.Commander()
        img = self.control.get_img_path("192.168.200.6", 'defaultlocal', 'winxp-IDE-002.img')
        self.control.create(self.vm, "192.168.200.6", img=img)
        self.vm.start()
        print self.vm.isStarted(120)
        time.sleep(10)
#        self.vm.restart()
#        time.sleep(40)
        self.vm.poweroff()
        time.sleep(20)        
        self.control.delete_vm("192.168.200.6", self.vm, False)
        #self.control.teardown()
        
    def testAnother(self):
        self.vm = vm.VMS("vm-test1")
        self.vm.set_cfg('numVcpusAllocated', '2')
        self.control = cmd.Commander()
        img = self.control.get_img_path("192.168.200.6", 'defaultlocal', 'winxp-IDE-002.img')
        self.control.create(self.vm, "192.168.200.6", img=img)
        self.vm.start()
        print self.vm.isStarted(120)
        time.sleep(10)
#        self.vm.restart()
#        time.sleep(40)
        self.vm.poweroff()
        time.sleep(20)        
        self.control.delete_vm("192.168.200.6", self.vm, False)
        #self.control.teardown()
        
    def testB(self):
        self.vm = vm.VMS("vm-test2")
        self.vm.set_cfg('numVcpusAllocated', '2')
        self.vm.set_cfg('memoryAllocatedInMb', '2048')
        self.control = cmd.Commander()
        img = self.control.get_img_path("192.168.200.6", 'defaultlocal', 'winxp-IDE-002.img')
        self.control.create(self.vm, "192.168.200.6", img=img)
        self.vm.start()
        print self.vm.isStarted(120)
        time.sleep(10)
#        self.vm.restart()
#        time.sleep(40)
        self.vm.poweroff()
        time.sleep(20)        
        self.control.delete_vm("192.168.200.6", self.vm, False)
        #self.control.teardown()


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()